<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Demo-08-计算属性</title>
    <script type="text/javascript" src="../JS/vue.js"></script>
</head>
<body>
<!-- computed 和 watch 之间的区别：
    1.computed 能完成的功能 watch 都可以完成;
    2.watch 能完成的功能 computed 不一定可以完成; 例如：watch 可以进行异步操作 -->

<div id="root">
    姓：<input v-model="firstName"><br>
    名：<input v-model="lastName"><br>
    全名：{{ fullName }}
</div>

<script text="text/javascript">
    const object = new Vue({
        el: '#root',

        data: {
            firstName: '张',
            lastName: '三',
            fullName: '张-三',
        },

        watch: {
            firstName: {
                handler(newValue, olderValue) {
                    this.fullName = newValue + '-' + this.lastName
                }
            },

            lastName: {
                handler(newValue, olderValue) {
                    this.fullName = this.firstName + '-' + newValue;
                }
            },
        }
    })
</script>
</body>
</html>